<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.fredck.FCKeditor.*,com.gouwudai.gobbs.pojo.TbbsClass,com.gouwudai.gobbs.pojo.TbbsTopic,com.gouwudai.gobbs.pojo.TbbsTopicRe,com.gouwudai.gobbs.pojo.TbbsTopicContent"%>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass2.jsp" %>
<%
int classId = ParamUtils.getIntParameter(request, "classId", 0);
int topicId =  ParamUtils.getIntParameter(request,"topicId");	
int topicReId =  ParamUtils.getIntParameter(request,"topicReId");	//要编辑的回复内容

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 权限验证模块 START *********************/
//判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//判断当前主题是否存在
ITopicService topicService = (ITopicService)BeanManager.getBean("topicService");
TbbsTopic tbbsTopic = null;

try
{
	tbbsTopic = topicService.load(new Integer(topicId));	
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的主题不存在或已被删除！");
	return;
}
//判断用户类型
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))	//验证用户是否为版主
{
	operatorType = 2;
}
else if(0==USER_ID.intValue())	//游客
{
	operatorType = -1;
}
else if(tbbsTopic.getUserId().intValue()==USER_ID.intValue())	//验证用户是否为主题作者
{
	operatorType = 1;
}

if(operatorType==2)	//版主
{
	userLogin.hasClassPermission(new Integer(classId),3001);	//版主编辑文章权限
}
/***************** 权限验证模块 END *********************/
//------------------- 拼导航菜单 -----------------
//分类相关属性
String className = currentClass.getClassName();
//目前支持3级栏目
Integer parentId = currentClass.getParentId();//父栏目ID，如果不为空则说明有父栏目
String parentName = "";
TbbsClass parentClass = null;
Integer grandId = null;//二级父栏目ID，如果不为空则说明有父栏目
String grandName = "";
TbbsClass grandIdClass = null;
if(parentId!=null&&parentId.intValue()>0)
{
	parentClass = classService.load(parentId);	
	parentName = parentClass.getClassName();
	grandId = parentClass.getParentId();
}
if(grandId!=null&&grandId.intValue()>0)
{
	grandIdClass = classService.load(grandId);	
	grandName = grandIdClass.getClassName();
}

StringBuilder totalClassName = new StringBuilder(50);//栏目全名，包括父栏目
if(grandId!=null&&grandId.intValue()>0)
{
	totalClassName.append(grandIdClass.getClassName());
	totalClassName.append(" - ");
}
if(parentId!=null&&parentId.intValue()>0)
{
	totalClassName.append(parentClass.getClassName());
	totalClassName.append(" - ");
}
totalClassName.append(currentClass.getClassName());
//--------------------- 拼导航菜单 ----------------------------
//--------------------- 读取主题信息 --------------------------
ITopicReService topicReService = (ITopicReService)BeanManager.getBean("topicReService");
ITopicContentService topicContentService = (ITopicContentService)BeanManager.getBean("topicContentService");
TbbsTopicRe tbbsTopicRe = null;
TbbsTopicContent tbbsTopicContent = null;

//1.判断当前版面是否存在
try
{
	tbbsTopicRe = topicReService.load(new Integer(topicReId));
	tbbsTopicContent = topicContentService.load(new Integer(topicReId));
}
catch(Exception e)
{
	HtmlConst.errors(out,6,"您浏览的主题内容不存在或已被删除！");
	return;
}
if(!tbbsTopicRe.getUserId().equals(userLogin.getUserId()))
{
	HtmlConst.errors(out,1,"您不能编辑他人主题，如果您还没有登陆，请先登陆！");
	return;
}
	
String title = tbbsTopicRe.getTitle();
boolean isTopicFlag = (tbbsTopic.getTopicReId().intValue()==topicReId)?true:false;	//当前编辑的是主题还是回复
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - 编辑主题 - <%=title %></title>
<meta name="Keywords" content="<%=SYSMETAKEY%>" />
<meta name="Description" content="<%=SYSMETADESC%>" />
<%@ include file="../common/meta.inc" %>
<link rel="stylesheet" type="text/css" href="css/defaultStyle.css" >
<script language="javascript" src="${pageContext.request.contextPath}/scripts/common-validator.js"></script>
<script language="javascript" type="text/javascript" src="scripts/showMenu.js"></script>
<script language="javascript" type="text/javascript" src="scripts/validateTopic.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
</head>
<body>
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">

setStatus('<%=SYSTITLE%> - 编辑主题 -  <%=title %>');

var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT);
function doSubmit() 
{	
	form = document.theform;
	if(!validateForm(form))
		return false;
		
    var obj = {};    
    
	obj[Buffalo.BOCLASS] = "java.util.HashMap";
	
	obj.isTopicFlag = <%=isTopicFlag%>;
	
	obj.topicId = <%=topicId%>;
	obj.topicReId = <%=topicReId%>;
	obj.title =  $F('title');
	obj.topicEditIp = "<%=userLogin.getLoginIp()%>";

	var titleColor =  " ";
	var titleBold =  0;	
	topicStyleListOld = "<%=tbbsTopicRe.getReStyleList()%>";
	var tempArray = topicStyleListOld.split(",");
	if(trim(tempArray[0])!="")
		titleColor = trim(tempArray[0]);
	<%//发表变色主题
	if(userLogin.withPermission(6002)){
	%>
		if(titleColor!="")
			titleColor =  $F('titleColor');
	<%}		
	//发表粗体主题
	if(userLogin.withPermission(6001)){
	%>		
		titleBold =  $F('titleBold');
	<%}%>	
	obj.topicStyleList = titleColor+","+titleBold;
	
	obj.topicMood = getRadioValue("topicMood");	//没有选择心情则默认心情	
	
	obj.content =  FCKeditorAPI.GetInstance('content').GetXHTML(true);
	obj.contentUserPen =  $F('contentUserPen');	
	obj.contentEmail = $F('contentEmail');
	obj.contentCopyright = getRadioValue('contentCopyright');	
	
	var url = "topic_post.jsp?action=edit&classId=<%=classId%>&topicId=<%=topicId%>"
    buffalo.remoteCall("topicServiceAjaxService.doEditTopic",[obj], function(reply) 
    {
        var ret = reply.getResult();
       	ajaxSubmit(ret,"","location",url);        
    });   
}

</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<DIV class="line"></DIV>
<DIV class="list_table_0">
<%=HtmlConst.navMenu(HtmlConst.navClassMenu(new Integer(classId),parentId,grandId,className,parentName,grandName ))%>&gt;&gt;编辑主题 -  <b><%=title %></b></DIV>
<DIV class="line"></DIV>
<form name="theform" id="theform" method="post" action="topic_post.jsp" onSubmit="return validateForm(this);">
<input name="action" type="hidden" value="edit" />
<input name="topicId" type="hidden" value="<%=topicId%>" />
<input name="topicReId" type="hidden" value="<%=topicReId%>" />
<input name="classId" type="hidden" value="<%=classId%>" />
<input name="parentId" type="hidden" value="<%=parentId%>" />
<input name="grandId" type="hidden" value="<%=grandId%>" />
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1" class="tab">
<tr>
<td width="80"  class="tab1"><strong>用户</strong></td>
<td class="bg2">
	<input name="loginId" type="text" id="loginId" value="<%=LOGIN_ID%>"  maxlength="50"  style="width:180px;height:20px" />
</td></tr>
<tr><td  class="tab1"><strong>密码</strong></td>
<td class="bg2">
	<input name="password" type="password" id="password" value="<%=userLogin.getPassword()%>" maxlength="50"  style="width:180px;height:20px"/>
	<input name="passwordOld" type="hidden" id="passwordOld" value="<%=userLogin.getPassword()%>"/>
</td></tr>
<tr><td  class="tab1"><strong>标题</strong></td>
<td class="bg2">
<input name="title" type="text" id="title" value="<%=tbbsTopicRe.getTitle() %>" maxlength="100" style="width:400px;height:20px"/>
<%//发表变色主题
if(userLogin.withPermission(6002)){
%>
<select name="titleColor" id="titleColor">
    <option selected value=" ">主题颜色</option>
    <option style="COLOR: #000000" value="black">■■■■</option>
    <option style="COLOR: #ff0000" value="#ff0000">■■■■</option>
    <option style="COLOR: #ffcc00" value="#ffcc00">■■■■</option>
    <option style="COLOR: #ff6699" value="#ff6699">■■■■</option>
    <option style="COLOR: #008800" value="#008800">■■■■</option>
    <option style="COLOR: orange" value="orange">■■■■</option>
    <option style="COLOR: #aa00cc" value="#aa00cc">■■■■</option>
    <option style="COLOR: #0000ff" value="#0000ff">■■■■</option>
    <option style="COLOR: #ccaa00" value="#ccaa00">■■■■</option>
    <option style="COLOR: #880000" value="#880000">■■■■</option>
    <option style="COLOR: teal" value="teal">■■■■</option>
    <option style="COLOR: #000088" value="#000088">■■■■</option>
	</select>
<%}
//发表粗体主题
if(userLogin.withPermission(6001)){
%>
&nbsp;<input name="titleBold" type="checkbox" id="titleBold" value="1">加粗
<%}%>
  </td>
</tr>
<tr id="load_<%=classId%>">
<td  class="tab1"><strong>心情</strong></td>
<td class="bg2">
<%for(int i=1; i<21; i++){%>
	<input type="radio" id="topicMood" name="topicMood" <%if(i==tbbsTopicRe.getReMood().intValue()) out.print("checked");%> value="<%=i%>"/>		
	<img alt="心情<%=i%>" src="images/mood/<%=i%>.gif" />&nbsp;&nbsp;
	<%if(i==10){ out.print("<br/>");}%>		
<%}%>
</tr>
<tr>
  <td  class="tab1"><strong>正文</strong></td>
  <td class="bg2">
 <%
FCKeditor oFCKeditor ;
oFCKeditor = new FCKeditor( request, "content" ) ;
oFCKeditor.setBasePath( contextPath+"/fckeditor/" ) ;
oFCKeditor.setValue(tbbsTopicContent.getContent());
oFCKeditor.setHeight("400");
FCKeditorConfigurations fckConfig = oFCKeditor.getConfig();
fckConfig.put("LinkBrowser","true");//超链浏览
fckConfig.put("ImageBrowser","true");//图片浏览
fckConfig.put("FlashBrowser","true");//FLASH浏览
fckConfig.put("LinkUpload","true");//文件上传
fckConfig.put("ImageUpload","true");//图片上传
fckConfig.put("FlashUpload","true");//FLASH上传
oFCKeditor.setConfig(fckConfig);
out.println( oFCKeditor.create() ) ;
%>
</td></tr>
<tr><td  class="tab1"><strong>上传附件</strong>
</td>
<td class="bg2">
<%

if(SYSINFO.getUpfileOpenFlag().booleanValue()&&userLogin.getUpfileOpenFlag().booleanValue()){%>
	<iframe name="uploadImg" frameborder="0" width="100%" height="30" scrolling="no" src="uploading/index.jsp?uploadType=2" allowTransparency="true"></iframe>
<%}else{	
	out.print("<span style=\"remark\">此功能已被关闭</span>");	
}
%>
</td></tr>
<tr><td  class="tab1"><strong>辅助</strong></td>
<td class="bg2">
<input name="contentUserPen" type="checkbox" value="true" <%if(tbbsTopicContent.getContentUserPen().booleanValue()) out.print("checked");%>/>显示签名&nbsp;&nbsp;
<input name="contentEmail" type="checkbox" value="true" <%if(tbbsTopicContent.getContentEmail().booleanValue()) out.print("checked");%>/>Email提醒
</td></tr>
<tr><td height="30" colspan="2"  class="tab1">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="btnSubmit" type="button" class="btn" id="btnSubmit" value="  确定提交  " onClick="doSubmit();"/>
&nbsp;&nbsp;&nbsp;&nbsp;
<button name="btnBack" class="btn" onClick="javascript:history.back();">取消</button>
</td></tr>
<tr><td height="30" colspan="2" class="tab1">
版权信息声明(仅代表发贴本人）：&nbsp;&nbsp;
<input id="contentCopyright" type="radio" name="contentCopyright" value="0" checked/>无版权声明&nbsp;&nbsp;
<input id="contentCopyright" type="radio" name="contentCopyright" value="1"/>本站独享&nbsp;&nbsp;
<input id="contentCopyright" type="radio" name="contentCopyright" value="2"/>网络共享&nbsp;&nbsp;
<input id="contentCopyright" type="radio" name="contentCopyright" value="3"/>非商业性共享
</td></tr></table>
</form>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>
</body>
</html>